'''
Created on 2014-2-6

@author: apple
'''
from com.ad.sword.dao.models import SystemConfig
from com.ad.sword.web.common import *
from com.ad.sword.service import SystemConfigService

@tojson
@check_required_argument
def set(request):
    for k, v in request.REQUEST.items():
        try:
            sc = SystemConfig.objects.get(name = k)
            if sc.value != v:
                sc.value = v
                sc.save()
        except DoesNotExist:
            continue

    return message(_("OK"))

@tojson
def list(request):
    return SystemConfigService.list()